/* Filter filter string */
function filterString(inputString) {
    var stringArray = inputString.split(" ");
    var filteredString = " ";
    var i;
    for (i=0; i < stringArray.length; i++) {
        if (stringArray[i] != "") {
            filteredString = filteredString.concat(stringArray[i] + " ");
        }
    }
    filteredString = filteredString.replace(/^\s/, "").replace(/\s$/, "");
    return filteredString;
}

function removeWhiteSpace(inputString) {
    var stringArray = inputString.split(" ");
    var filteredString = " ";
    var i;
    for (i=0; i < stringArray.length; i++) {
        if (stringArray[i] != "") {
            filteredString = filteredString.concat(stringArray[i] + " ");
        }
    }
    filteredString = filteredString.replace(/^\s/, "").replace(/\s$/, "");
    if (filteredString == " ") {
        return NaN;
    }
    return filteredString;
}

function countWhiteSpace(inputString) {
    var count = 0;
    var i;
    for (i = 0; i < inputString.length; i++) {
        if (inputString.charAt(i) == ' ') {
            ++count;
        }
    }
    return count;
}

function validateCost(inputCost) {
    var resultArray = new Array(2);
    var filteredCost = filterString(inputCost);
    var patt = /^[0-9\.]*$/
    
    if (!patt.test(filteredCost)) {
        resultArray[0] = "1";
        resultArray[1] = "None";
    } else {
        var i;
        var spaceCount = 0;
        var dotCount = 0;
        for (i = 0; i < filteredCost.length; i++) {
            if (filteredCost.charAt(i) == " ") {
                ++spaceCount;
            }
            if (filteredCost.charAt(i) == ".") {
                ++dotCount;
            }
        }
        if (spaceCount > 0 || dotCount > 1) {
            resultArray[0] = "1";
            resultArray[1] = "None";
        } else if (filteredCost.length > 11) {
            resultArray[0] = "2";
            resultArray[1] = "None";
        } else {
            resultArray[0] = "3";
            resultArray[1] = filteredCost;
        }
    }
    return resultArray;
}

/* Check Request input */
function checkRequest(event) {
    var request = document.forms["claimForm"]["request"].value;
    var requestString = filterString(request);
    var count = countWhiteSpace(requestString);
    var message = document.getElementById("requestMessage");

    switch (event) {
        case 0: {
            message.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            if (requestString == "") {
                message.innerHTML = "The request must not be empty.";
                return false;
            } else {
                if((requestString.length-count+1) > 255) {
                    message.innerHTML = "The number of the characters must be less 255. " + (requestString.length-count+1) + " " + requestString;
                    return false;
                } 
                    
                var patt = /^[a-zA-Z0-9\s]*$/;
                if (!patt.test(requestString)) {
                    message.innerHTML = "The request only includes alphanumeric";
                    return false;
                }   
            } 
        }
        break;
        default: {
            }
            break;
    }
    return true;
}

/* Check Provider input */
function checkProvider(event) {
    var provider = document.forms["claimForm"]["provider"].value;
    var providerString = filterString(provider);
    var count = countWhiteSpace(providerString);
    var providerMessage = document.getElementById("providerMessage");
    
    switch (event) {
        case 0: {
            providerMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            if (providerString == "") {
                providerMessage.innerHTML = "The provider name must not be empty.";
                return false;
            } else {
                if((providerString.length-count+1) > 255) {
                    providerMessage.innerHTML = "The number of the characters must be less 255.";
                    return false;
                } 
                    
                var patt = /^[a-zA-Z0-9\s\.\(\)\\\-\+\/]*$/;
                if (!patt.test(providerString)) {
                    providerMessage.innerHTML = "The provider name only includes alphanumeric and some special character";
                    return false;
                }   
            } 
        }
        break;
        default: {
            }
            break;
    }
    return true;
}

/* Check Address input */
function checkAddress(event) {
    var address = document.forms["claimForm"]["address"].value;
    var addressString = filterString(address);
    var count = countWhiteSpace(addressString);
    var addressMessage = document.getElementById("addressMessage");

    switch (event) {
        case 0: {
            addressMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            if (addressString == "") {
                addressMessage.innerHTML = "The address must not be empty.";
                return false;
            } else {
                if((addressString.length-count+1) > 255) {
                    addressMessage.innerHTML = "The number of the characters must be less 255.";
                    return false;
                } 
                    
                var patt = /^[a-zA-Z0-9\s\.\(\)\\\-\+\/]*$/;
                if (!patt.test(addressString)) {
                    addressMessage.innerHTML = "The provider name only includes alphanumeric and some special character";
                    return false;
                }   
            } 
        }
        break;
        default: {
            }
            break;
    }
    return true;
}

/* Check Phone Number input */
function checkPhoneNumber(event) {
    var phoneNumber = document.forms["claimForm"]["phoneNumber"].value;
    var phoneNumberString = filterString(phoneNumber);
    var phoneNumberMessage = document.getElementById("phoneNumberMessage");

    switch (event) {
        case 0: {
            phoneNumberMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            if (phoneNumberString.length != 0) {
                var patt = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
                if (!patt.test(phoneNumberString)) {
                    phoneNumberMessage.innerHTML = "The phone number must have format (xxx)-xxx-xxxx.";
                    return false;
                }
            } 
        }
        break;
        default: {
            }
            break;
    }
    return true;
}

/* Email input */
function checkEmail(event) {
    var email = document.forms["claimForm"]["email"].value;
    var emailString = filterString(email);
    var emailMessage = document.getElementById("emailMessage");

    switch (event) {
        case 0: {
            emailMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            if (emailString.length != 0) {
                var patt = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
                if (!patt.test(emailString)) {
                    emailMessage.innerHTML = "The email is invalid.";
                    return false;
                }
            }
        }
        break;
        default: {
            }
            break;
    }
    return true;
}

/* Expense Date input */
function checkExpenseDate(event) {
    var expenseDate = document.forms["claimForm"]["datepicker"].value;
    var expenseDateString = filterString(expenseDate);
    var expenseDateMessage = document.getElementById("expenseDateMessage");
    
    switch (event) {
        case 0: {
            expenseDateMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            if (expenseDateString == "") {
                expenseDateMessage.innerHTML = "The expense date must not be empty.";
                return false;
            } else {
                if ((Date.parse(expenseDateString).toString()) == "NaN") {
                    expenseDateMessage.innerHTML = "The expense date is invalid.";
                    return false;
                }
            }
            expenseDateMessage.innerHTML = "";
        }
        break;
        default: {
            }
            break;
    }
    return true;
}

/* Variable of cost */
var medicineCost = 0;
var laboratoryCost = 0;
var surgeryCost = 0;
var otherItemsCost = 0;
var totalCost1 = 0;
var totalCost2 = 0;
var totalCost3 = 0;
var totalCost4 = 0;
var total;

/* Check Medicine input */
function checkMedicine(event) {
    var medicine = document.forms["claimForm"]["medicine"].value;
    var medicineMessage = document.getElementById("medicineMessage");
    var cOMedicine = document.forms["claimForm"]["costOfMedicine"].value; 
    var costOfMedicineMessage = document.getElementById("costOfMedicineMessage");
    
    var medicineString = removeWhiteSpace(medicine);
    var cOMedicineString = removeWhiteSpace(cOMedicine);
    var count = countWhiteSpace(medicineString);

    switch (event) {
        case 0: {
            medicineMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            checkCostOfMedicine(1);
            if ((medicineString.length != 0 && cOMedicineString.length == 0)) {
                document.getElementById("rs1").innerHTML = medicineString.length + " " + cOMedicineString.length;
                costOfMedicineMessage.innerHTML = "The cost of the medicine must not be empty.";
                return false;
            } else if ((medicineString.length == 0 && cOMedicineString.length != 0)) {
                document.getElementById("rs1").innerHTML = medicineString.length + " " + cOMedicineString.length;
                medicineMessage.innerHTML = "The medicine must not be empty.";
                return false;
            } else {
                if((medicineString.length-count+1) > 255) {
                    medicineMessage.innerHTML = "The number of the characters must be less 255.";
                    return false;
                } 
                    
                var patt = /^[a-zA-Z0-9\s\.\(\)\\\-\+\/]*$/;
                if (!patt.test(medicineString)) {
                    medicineMessage.innerHTML = "The medicine only includes alphanumeric and some special character";
                    return false;
                }   
            } 
        }
        break;
        default: {
            }
            break;
    }
    medicineMessage.innerHTML = "";
    costOfMedicineMessage.innerHTML = "";
    return true;
}


/* Check Cost of Medicine input */
function checkCostOfMedicine(event) {
    var cOMedicine = document.forms["claimForm"]["costOfMedicine"].value;
    var costOfMedicineMessage = document.getElementById("costOfMedicineMessage");
    var medicine = document.getElementById("medicine").value;
    var medicineMessage = document.getElementById("medicineMessage");
    
    var medicineString = removeWhiteSpace(medicine);
    var cOMedicineString = removeWhiteSpace(cOMedicine);
    
    switch (event) {
        case 0: {
            costOfMedicineMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            if ((medicineString.length != 0 && cOMedicineString.length == 0)) {
                document.getElementById("rs1").innerHTML = medicineString.length + " " + cOMedicineString.length;
                costOfMedicineMessage.innerHTML = "The cost of the medicine must not be empty.";
                return false;
            } else if ((medicineString.length == 0 && cOMedicineString.length != 0)) {
                document.getElementById("rs1").innerHTML = medicineString.length + " " + cOMedicineString.length;
                medicineMessage.innerHTML = "The medicine must not be empty.";
                return false;
            } else {
                medicineCost = 0;
                var resultArray = validateCost(cOMedicineString);
                var item1 = resultArray[0].toString();
                var item2 = resultArray[1].toString();
                document.getElementById("rs1").innerHTML = item2 + " " + parseFloat(item2);
                if (item1 == "1") {
                    costOfMedicineMessage.innerHTML = "The cost of medicine is invalid";
                    return false;
                } 
                if (item1 == "2") {
                    costOfMedicineMessage.innerHTML = "The number of the characters must be less 11";
                    return false;
                }
                if (item1 == "3") {
                    medicineCost = parseFloat(item2);
                }
            }
        }
        break;
        case 2: {
            }
            break;
        default: {
                
            }
            break;
    }
    medicineMessage.innerHTML = "";
    costOfMedicineMessage.innerHTML = "";
    if (medicineCost.toString() == "NaN") {
        medicineCost = 0;
    }
    totalCost1 = medicineCost + laboratoryCost + surgeryCost + otherItemsCost;
    document.getElementById("totalOfCost").innerHTML = totalCost1.toString();
    return true;
}

/* Check Laboratory Test input */
function checkLaboratoryTest(event) {
    var laboratoryTest = document.forms["claimForm"]["laboratoryTest"].value;
    var laboratoryTestMessage = document.getElementById("laboratoryTestMessage");
    var cOLaboratoryTest = document.forms["claimForm"]["costOfLaboratoryTest"].value; 
    var costOfLaboratoryTestMessage = document.getElementById("costOfLaboratoryTestMessage");
    
    var laboratoryTestString = removeWhiteSpace(laboratoryTest);
    var cOLaboratoryTestString = removeWhiteSpace(cOLaboratoryTest);
    var count = countWhiteSpace(laboratoryTestString);

    switch (event) {
        case 0: {
            laboratoryTestMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            checkCostOfLaboratoryTest(1);
            if ((laboratoryTestString.length != 0 && cOLaboratoryTestString.length == 0)) {
                document.getElementById("rs2").innerHTML = laboratoryTestString.length + " " + cOLaboratoryTestString.length;
                costOfLaboratoryTestMessage.innerHTML = "The cost of the laboratory test must not be empty.";
                return false;
            } else if ((laboratoryTestString.length == 0 && cOLaboratoryTestString.length != 0)) {
                document.getElementById("rs2").innerHTML = laboratoryTestString.length + " " + cOLaboratoryTestString.length;
                laboratoryTestMessage.innerHTML = "The laboratory test must not be empty.";
                return false;
            } else {
                if((laboratoryTestString.length-count+1) > 255) {
                    laboratoryTestMessage.innerHTML = "The number of the characters must be less 255.";
                    return false;
                } 
                    
                var patt = /^[a-zA-Z0-9\s\.\(\)\\\-\+\/]*$/;
                if (!patt.test(laboratoryTestString)) {
                    laboratoryTestMessage.innerHTML = "The laboratory test only includes alphanumeric and some special character";
                    return false;
                }   
            } 
        }
        break;
        default: {
            }
            break;
    }
    laboratoryTestMessage.innerHTML = "";
    costOfLaboratoryTestMessage.innerHTML = "";
    return true;
}

/* Check Cost of Laboratory Test input */
function checkCostOfLaboratoryTest(event) {
    var laboratoryTest = document.forms["claimForm"]["laboratoryTest"].value;
    var laboratoryTestMessage = document.getElementById("laboratoryTestMessage");
    var cOLaboratoryTest = document.forms["claimForm"]["costOfLaboratoryTest"].value; 
    var costOfLaboratoryTestMessage = document.getElementById("costOfLaboratoryTestMessage");
    
    var laboratoryTestString = removeWhiteSpace(laboratoryTest);
    var cOLaboratoryTestString = removeWhiteSpace(cOLaboratoryTest);
    
    switch (event) {
        case 0: {
            costOfLaboratoryTestMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            if ((laboratoryTestString.length != 0 && cOLaboratoryTestString.length == 0)) {
                document.getElementById("rs2").innerHTML = laboratoryTestString.length + " " + cOLaboratoryTestString.length;
                costOfLaboratoryTestMessage.innerHTML = "The cost of the laboratory test must not be empty.";
                return false;
            } else if ((laboratoryTestString.length == 0 && cOLaboratoryTestString.length != 0)) {
                document.getElementById("rs2").innerHTML = laboratoryTestString.length + " " + cOLaboratoryTestString.length;
                laboratoryTestMessage.innerHTML = "The laboratory test must not be empty.";
                return false;
            } else {
                laboratoryCost = 0;
                var resultArray = validateCost(cOLaboratoryTestString);
                var item1 = resultArray[0].toString();
                var item2 = resultArray[1].toString();
                document.getElementById("rs2").innerHTML = item2 + " " + parseFloat(item2);
                if (item1 == "1") {
                    costOfLaboratoryTestMessage.innerHTML = "The cost of laboratory test is invalid";
                    return false;
                } 
                if (item1 == "2") {
                    costOfLaboratoryTestMessage.innerHTML = "The number of the characters must be less 11";
                    return false;
                }
                if (item1 == "3") {
                    laboratoryCost = parseFloat(item2);
                }
            }
        }
        break;
        case 2: {
            }
            break;
        default: {
                
            }
            break;
    }
    laboratoryTestMessage.innerHTML = "";
    costOfLaboratoryTestMessage.innerHTML = "";
    if (laboratoryCost.toString() == "NaN") {
        laboratoryCost = 0;
    }
    totalCost2 = medicineCost + laboratoryCost + surgeryCost + otherItemsCost;
    document.getElementById("totalOfCost").innerHTML = totalCost2.toString();
    return true;
}

/* Check Surgery input */
function checkSurgery(event) {
    var surgery = document.forms["claimForm"]["surgery"].value;
    var surgeryMessage = document.getElementById("surgeryMessage");
    var cOSurgery = document.forms["claimForm"]["costOfSurgery"].value; 
    var costOfSurgeryMessage = document.getElementById("costOfSurgeryMessage");
    
    var surgeryString = removeWhiteSpace(surgery);
    var cOSurgeryString = removeWhiteSpace(cOSurgery);
    var count = countWhiteSpace(surgeryString);

    switch (event) {
        case 0: {
            surgeryMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            checkCostOfSurgery(1);
            if ((surgeryString.length != 0 && cOSurgeryString.length == 0)) {
                document.getElementById("rs3").innerHTML = surgeryString.length + " " + surgeryString.length;
                costOfSurgeryMessage.innerHTML = "The cost of the laboratory test must not be empty.";
                return false;
            } else if ((surgeryString.length == 0 && cOSurgeryString.length != 0)) {
                document.getElementById("rs3").innerHTML = surgeryString.length + " " + cOSurgeryString.length;
                surgeryMessage.innerHTML = "The laboratory test must not be empty.";
                return false;
            } else {
                if((surgeryString.length-count+1) > 255) {
                    surgeryMessage.innerHTML = "The number of the characters must be less 255.";
                    return false;
                } 
                    
                var patt = /^[a-zA-Z0-9\s\.\(\)\\\-\+\/]*$/;
                if (!patt.test(surgeryString)) {
                    surgeryMessage.innerHTML = "The laboratory test only includes alphanumeric and some special character";
                    return false;
                }   
            } 
        }
        break;
        default: {
            }
            break;
    }
    surgeryMessage.innerHTML = "";
    costOfSurgeryMessage.innerHTML = "";
    return true;
}

/* Cost of Surgery input */
function checkCostOfSurgery(event) {
    var surgery = document.forms["claimForm"]["surgery"].value;
    var surgeryMessage = document.getElementById("surgeryMessage");
    var cOSurgery = document.forms["claimForm"]["costOfSurgery"].value; 
    var costOfSurgeryMessage = document.getElementById("costOfSurgeryMessage");
    
    var surgeryString = removeWhiteSpace(surgery);
    var cOSurgeryString = removeWhiteSpace(cOSurgery);
    
    
    switch (event) {
        case 0: {
            costOfSurgeryMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            if ((surgeryString.length != 0 && cOSurgeryString.length == 0)) {
                document.getElementById("rs3").innerHTML = surgeryString.length + " " + cOSurgeryString.length;
                costOfSurgeryMessage.innerHTML = "The cost of the laboratory test must not be empty.";
                return false;
            } else if ((surgeryString.length == 0 && cOSurgeryString.length != 0)) {
                document.getElementById("rs3").innerHTML = surgeryString.length + " " + cOSurgeryString.length;
                surgeryMessage.innerHTML = "The laboratory test must not be empty.";
                return false;
            } else {
                surgeryCost = 0;
                var resultArray = validateCost(cOSurgeryString);
                var item1 = resultArray[0].toString();
                var item2 = resultArray[1].toString();
                document.getElementById("rs3").innerHTML = item2 + " " + parseFloat(item2);
                if (item1 == "1") {
                    costOfSurgeryMessage.innerHTML = "The cost of laboratory test is invalid";
                    return false;
                } 
                if (item1 == "2") {
                    costOfSurgeryMessage.innerHTML = "The number of the characters must be less 11";
                    return false;
                }
                if (item1 == "3") {
                    surgeryCost = parseFloat(item2);
                }
            }
        }
        break;
        case 2: {
            }
            break;
        default: {
                
            }
            break;
    }
    surgeryMessage.innerHTML = "";
    costOfSurgeryMessage.innerHTML = "";
    if (surgeryCost.toString() == "NaN") {
        surgeryCost = 0;
    }
    totalCost3 = medicineCost + laboratoryCost + surgeryCost + otherItemsCost;
    document.getElementById("totalOfCost").innerHTML = totalCost3.toString();
    return true;
}

/* Check Other Items input */
function checkOtherItems(event) {
    var otherItems = document.forms["claimForm"]["otherItems"].value;
    var otherItemsMessage = document.getElementById("otherItemsMessage");
    var cOOtherItems = document.forms["claimForm"]["costOfOtherItems"].value; 
    var costOfOtherItemsMessage = document.getElementById("costOfOtherItemsMessage");
    
    var otherItemsString = removeWhiteSpace(otherItems);
    var cOOtherItemsString = removeWhiteSpace(cOOtherItems);
    var count = countWhiteSpace(otherItemsString);

    switch (event) {
        case 0: {
            otherItemsMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            checkCostOfOtherItems(1);
            if ((otherItemsString.length != 0 && cOOtherItemsString.length == 0)) {
                document.getElementById("rs4").innerHTML = otherItemsString.length + " " + cOOtherItemsString.length;
                costOfOtherItemsMessage.innerHTML = "The cost of the other items must not be empty.";
                return false;
            } else if ((otherItemsString.length == 0 && cOOtherItemsString.length != 0)) {
                document.getElementById("rs4").innerHTML = otherItemsString.length + " " + cOOtherItemsString.length;
                otherItemsMessage.innerHTML = "The other items must not be empty.";
                return false;
            } else {
                if((otherItemsString.length-count+1) > 255) {
                    otherItemsMessage.innerHTML = "The number of the characters must be less 255.";
                    return false;
                } 
                    
                var patt = /^[a-zA-Z0-9\s\.\(\)\\\-\+\/]*$/;
                if (!patt.test(otherItemsString)) {
                    otherItemsMessage.innerHTML = "The other items only includes alphanumeric and some special character";
                    return false;
                }   
            } 
        }
        break;
        default: {
            }
            break;
    }
    otherItemsMessage.innerHTML = "";
    costOfOtherItemsMessage.innerHTML = "";
    return true;
}

/* Cost of Other items input */
function checkCostOfOtherItems(event) {
    var otherItems = document.forms["claimForm"]["otherItems"].value;
    var otherItemsMessage = document.getElementById("otherItemsMessage");
    var cOOtherItems = document.forms["claimForm"]["costOfOtherItems"].value; 
    var costOfOtherItemsMessage = document.getElementById("costOfOtherItemsMessage");
    
    var otherItemsString = removeWhiteSpace(otherItems);
    var cOOtherItemsString = removeWhiteSpace(cOOtherItems);
    

    switch (event) {
        case 0: {
            costOfOtherItemsMessage.innerHTML = "";
            return false;
        }
        break;
        case 1: {
            if ((otherItemsString.length != 0 && cOOtherItemsString.length == 0)) {
                document.getElementById("rs4").innerHTML = otherItemsString.length + " " + cOOtherItemsString.length;
                costOfOtherItemsMessage.innerHTML = "The cost of the other items must not be empty.";
                return false;
            } else if ((otherItemsString.length == 0 && cOOtherItemsString.length != 0)) {
                document.getElementById("rs4").innerHTML = otherItemsString.length + " " + cOOtherItemsString.length;
                otherItemsMessage.innerHTML = "The other items must not be empty.";
                return false;
            } else {
                otherItemsCost = 0;
                var resultArray = validateCost(cOOtherItemsString);
                var item1 = resultArray[0].toString();
                var item2 = resultArray[1].toString();
                document.getElementById("rs4").innerHTML = item2 + " " + parseFloat(item2);
                if (item1 == "1") {
                    costOfOtherItemsMessage.innerHTML = "The cost of other items is invalid";
                    return false;
                } 
                if (item1 == "2") {
                    costOfOtherItemsMessage.innerHTML = "The number of the characters must be less 11";
                    return false;
                }
                if (item1 == "3") {
                    otherItemsCost = parseFloat(item2);
                }
            }
        }
        break;
        case 2: {
            }
            break;
        default: {
                
            }
            break;
    }
    otherItemsMessage.innerHTML = "";
    costOfOtherItemsMessage.innerHTML = "";
    if (otherItemsCost.toString() == "NaN") {
        otherItemsCost = 0;
    }
    totalCost4 = medicineCost + laboratoryCost + surgeryCost + otherItemsCost;
    document.getElementById("totalOfCost").innerHTML = totalCost4.toString();
    return true;
}

/* Check Note input */


function checkFillingCost() {
    if (totalCost1 == 0 && totalCost2 == 0 && totalCost3 == 0 && totalCost4 == 0) {
        document.getElementById("fillingCostMessage").innerHTML = "At least one field of cost must be filled.";
        return false;
    }
    
    document.getElementById("fillingCostMessage").innerHTML = "";
    return true;
    
}

/* Clear all the cost */
function clearTotalCost() {
    medicineCost = 0;
    laboratoryCost = 0;
    surgeryCost = 0;
    otherItemsCost = 0;
    total = 0;
    document.getElementById("totalOfCost").innerHTML = total.toString();
}

/* Claim Form */
function validateClaimForm() {
    var flagArray = new Array(11);
    var i;
    
    for(i = 0; i < 11; i++) {
        flagArray[i] = 0;
    }
    
    if (checkRequest(1)) {
        flagArray[0] = 1;
    }
    if (checkProvider(1)) {
        flagArray[1] = 1;
    }
    if (checkAddress(1)) {
        flagArray[2] = 1;
    }
    if (checkPhoneNumber(1)) {
        flagArray[3] = 1;
    }
    if (checkEmail(1)) {
        flagArray[4] = 1;
    }
    
    if (checkExpenseDate(1)) {
        flagArray[5] = 1;
    }
    
    if (checkCostOfMedicine(1)) {
        flagArray[6] = 1;
    }
    if (checkCostOfLaboratoryTest(1)) {
        flagArray[7] = 1;
    }
    if (checkCostOfSurgery(1)) {
        flagArray[8] = 1;
    }
    if (checkCostOfOtherItems(1)) {
        flagArray[9] = 1;
    }
    
    if (checkFillingCost()) {
        flagArray[10] = 1;
    }
    
    var count=0;
    for (i = 0; i < 11; i++) {
        count += flagArray[i];
    }
    document.getElementById("test").innerHTML = count.toString();
    
    if (count > 10) {
        var cf = window.confirm("Are you want to sending the claim to the our system?");
        if (cf == true) {
            return true;
        }
    } 
    
    return false;
}

function showRequestResult() {
    var requestResult = document.getElementById("requestResult").value;
    if (requestResult.length != 0) {
        window.alert(requestResult);
    }
}